//
//  GreenViewController.m
//  TestPushAndPresent
//
//  Created by sunhongyue on 2017/6/25.
//  Copyright © 2017年 sunhongyue. All rights reserved.
//

#import "GreenViewController.h"

@interface GreenViewController ()

@end

@implementation GreenViewController

- (instancetype)init {
    if (self = [super init]) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"greenVC";
    self.view.backgroundColor = [UIColor greenColor];
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithTitle:@"第一个" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarItemAction:)];
    self.navigationItem.leftBarButtonItem = leftBarItem;
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectZero];
    [self.view addSubview:button];
    button.translatesAutoresizingMaskIntoConstraints = NO;
    [button.widthAnchor constraintEqualToConstant:100.0].active = YES;
    [button.heightAnchor constraintEqualToConstant:50.0].active = YES;
    [button.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES;
    [button.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor].active = YES;
    [button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"dismiss Self" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor blueColor];
}

- (void)leftBarItemAction:(id)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)btnAction:(UIButton *)sender {
    UIViewController *vc = [[self presentingViewController] presentingViewController];
    [vc dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
